View Javadoc
1 /* 2 * Copyright (c) 2001 by 3 * Siegfried GOESCHL <mailto:siegfried.goeschl@itserv.at>; 4 * and Dima STADNIK <mailto:5d5@mail.ru>; 5 * 6 * This program is free software. 7 * 8 * You may redistribute it and/or modify it under the terms of the GNU 9 * General Public License as published by the Free Software Foundation. 10 * Version 2 of the license should be included with this distribution in 11 * the file LICENSE, as well as License.html. If the license is not 12 * included with this distribution, you may find a copy at the FSF web 13 * site at 'www.gnu.org' or 'www.fsf.org', or you may write to the 14 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA. 15 * 16 * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, 17 * NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR 18 * OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY 19 * CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR 20 * REDISTRIBUTION OF THIS SOFTWARE. 21 */ 22 23 package junit.extensions; 24 25 import junit.framework.Test; 26 import junit.framework.TestResult; 27 28 29 /*** 30 * A Decorator that runs a test in a separate thread. 31 * 32 * @author Siegfried GOESCHL 33 */ 34 public class ActiveTest extends TestDecorator { 35 36 /*** Stress level. */ 37 private int multiplier = 1; 38 39 /*** Target test. */ 40 private Test test; 41 42 /*** 43 * Thread that executes test. 44 */ 45 private class Executor extends Thread { 46 47 TestResult testResult; 48 49 Executor(TestResult testResult) { 50 this.testResult = testResult; 51 } 52 53 public void run() { 54 test.run(testResult); 55 } 56 } 57 58 /*** 59 * Creates active test with default multiplier (1). 60 * 61 * @param test Target test. 62 */ 63 public ActiveTest(Test test) { 64 super(test); 65 this.test = test; 66 } 67 68 /*** 69 * Creates active test with default multiplier (1). 70 * 71 * @param test Target test. 72 * @param multiplier Stress level. 73 */ 74 public ActiveTest(Test test, int multiplier) { 75 super(test); 76 this.test = test; 77 this.multiplier = multiplier; 78 } 79 80 public void run(TestResult testResult) { 81 Executor[] threads = new Executor[multiplier]; 82 83 for (int i = 0; i < multiplier; i++) { 84 threads[i] = new Executor(testResult); 85 } 86 for (int i = 0; i < multiplier; i++) { 87 threads[i].start(); 88 } 89 for (int i = 0; i < multiplier; i++) { 90 try { 91 threads[i].join(); 92 } catch (InterruptedException e) {} 93 } 94 } 95 96 public String toString() { 97 return super.toString() + " (active)"; 98 } 99 }

This page was automatically generated by Maven